$(function () {
    $("#jqGrid").jqGrid({
        url: '../payorder/list',
        postData:{
            category:0
        },
        datatype: "json",
        colModel: [
            {
                label: '订单号', name: 'recordno', index: 'recordNo', width: 180,
                formatter: function (value, options, row) {
                    return '<a onclick="showInfo('+row.id+',\''+value+'\')" target="view_window">'+value+'</a>';
                }
            },
            {label: '订单创建时间', name: 'orderdate', index: 'orderdate', width: 160},
            {
                label: '来源', name: 'resource', index: 'resource', width: 60,
                formatter: function (value, options, row) {
                    if (value == 0) {
                        return "微信";
                    } else if (value == 1) {
                        return "支付宝";
                    }
                }
            },
            {label: '收款员名称', name: 'name', index: 'name', width: 100},
            {label: '支付状态', name: 'status', index: 'status', width: 100,
                formatter: function (value, options, row) {
                    if (value == 0) {return "支付失败";
                    } else if (value == 1) {return "已付款";
                    }else if (value == 2) {return "已退款";
                    }else if (value == 3) {return "已对账";
                    }else if (value == 4) {return "已关闭";
                    }else if (value == 5) {return "退款处理中";
                    }else if (value == 6) {return "未确定，需重新发起";
                    }else if (value == 7) {return "转入代发";
                    }else if (value == 9) {return "异常";
                    }else if (value == 10) {return "转入退款";
                    }else if (value == 11) {return "未支付";
                    }else if (value == 12) {return "已冲正";
                    }else if (value == 13) {return "已撤销";
                    }else if (value == 14) {return "退款失败";
                    }else{
                        return "";
                    }
                }},
            {label: '金额', name: 'amount', index: 'amount', width: 80},
            {label: '用户备注', name: 'payremark', index: 'payremark', width: 200},
            {label: '银行类型', name: 'bankTypeVue', index: 'bank_type', width: 180},
            {label: '收款码编号', name: 'codeNo', index: 'code_no', width: 150},
            {label: '商户号', name: 'busid', index: 'busId', width: 180},
            {label: '收款码名称', name: 'codeName', index: 'code_name', width: 100},
            {label: '店铺名称', name: 'shopname', index: 'shopname', width: 250},
            {label: '备注', name: 'remark', index: 'remark', width: 200}
           
        ],
        viewrecords: true,
        height: "98%",
        rowNum: 10,
        rowList: [10, 20,30],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        shrinkToFit:false,//显示底部水平滚动条
        autoScroll: true,//显示底部水平滚动条
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            //$("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        payorder: {}
    },
    methods: {
        query: function () {
            vm.reload();
        },
        saveOrUpdate: function (event) {
            var url = vm.payorder.id == null ? "../payorder/save" : "../payorder/update";
            $.ajax({
                type: "POST",
                url: url,
                data: JSON.stringify(vm.payorder),
                success: function (r) {
                    if (r.code === 0) {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        getInfo: function (id) {
            $.get("../payorder/info/" + id, function (r) {
                vm.payorder = r.payorder;
            });
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            page = 1;
            var recordno = $("#recordno").val();//订单号
            var orderdateBegin = $("#orderdateBegin").val();//开始时间
            var orderdateEnd = $("#orderdateEnd").val();//结束时间
            var resource = $("#resource").val();//来源
            var status = $("#status").val();//订单状态
            var cashiersName = $("#cashiersName").val();//收款员名称
            var codeNo = $("#codeNo").val();//收款码编号
            var shopname = $("#shopname").val();//店铺名称
            if(orderdateBegin!=""&&orderdateBegin!=null){
                orderdateBegin=orderdateBegin+" 00:00:01";
            }
            if(orderdateEnd!=""&&orderdateEnd!=null){
                orderdateEnd=orderdateEnd+" 23:59:59";
            }
            $("#jqGrid").jqGrid('setGridParam', {
                page: page,
                postData:{recordno:recordno,
                	resource:resource,
                	orderdateBegin:orderdateBegin,
                	orderdateEnd:orderdateEnd,
                	status:status,
                	cashiersName:cashiersName,
                	codeNo:codeNo,
                	shopname:shopname
                	},
            }).trigger("reloadGrid");
        }
    }
});

function showInfo(id,vaue){
    parent.layer.open({
        type: 2,
        title: '订单详情',
        shadeClose: true,
        shade: 0.8,
        fixed: false, //不固定
        maxmin: true,
        area: ['60%', '60%'],
        content: 'pay/payOrderView.html?id='+id+"&orderid="+vaue //iframe的url
    });
}
